package com.xy.novelweb.interceptor;

import com.xy.novelweb.domain.Reader;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.servlet.HandlerInterceptor;
import org.springframework.web.servlet.ModelAndView;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
@Slf4j
public class BookShelfInterceptor implements HandlerInterceptor {
		@Override
		public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws Exception {
				Reader reader = (Reader) request.getSession().getAttribute("user_reader");
				log.info("拦截到请求...");
				boolean flag = false;
				if (reader != null && reader.getNickName() != null && !"".equals(reader.getNickName())) {
						flag = true;
				} else {
						response.setContentType("text/html;charset=UTF-8");
						response.sendRedirect("/wfRead/loginAndRegist/unlogin");
				}
				return flag;
		}

		@Override
		public void postHandle(HttpServletRequest request, HttpServletResponse response, Object handler, ModelAndView modelAndView) throws Exception {

		}

		@Override
		public void afterCompletion(HttpServletRequest request, HttpServletResponse response, Object handler, Exception ex) throws Exception {

		}
}